<HTML>
<HEAD>
<TITLE>
FileReader.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="blue">#include</font><font color="maroon">&#60;fstream&#62;</font>
<font color="blue">#include</font><font color="maroon">&#60;cstring&#62;</font>
<font color="blue">#include</font><font color="maroon">"FileReader.h"</font>
<font color="blue">#include</font><font color="maroon">&#60;iostream&#62;</font>


<font color="blue">using</font> <font color="blue">namespace</font> std;

FileReader<font color="black">:</font><font color="black">:</font>FileReader<font color="black">(</font><font color="blue">const</font> <font color="blue">char</font><font color="black">*</font> str<font color="black">)</font>
<font color="black">{</font>
    linepos <font color="black">=</font> <font color="maroon">0</font>;
    bufsize <font color="black">=</font> <font color="maroon">0</font>;
    strcpy<font color="black">(</font>filename,str<font color="black">)</font>;
    FileReader<font color="black">:</font><font color="black">:</font>openline<font color="black">(</font><font color="black">)</font>;
<font color="black">}</font>

FileReader<font color="black">:</font><font color="black">:</font>~FileReader<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    FileReader<font color="black">:</font><font color="black">:</font>closeline<font color="black">(</font><font color="black">)</font>;
<font color="black">}</font>

<font color="blue">bool</font> FileReader<font color="black">:</font><font color="black">:</font>m_openFile<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    ifstream myfile<font color="black">(</font>filename,ios_base<font color="black">:</font><font color="black">:</font>in<font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font>myfile<font color="black">)</font>
        <font color="blue">return</font> <font color="maroon">1</font>;
    <font color="blue">else</font>
        <font color="blue">return</font> <font color="maroon">0</font>;
    
<font color="black">}</font>

<font color="blue">void</font> FileReader<font color="black">:</font><font color="black">:</font>openline<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    myfile.open<font color="black">(</font>filename,ios_base<font color="black">:</font><font color="black">:</font>in<font color="black">)</font>;
<font color="black">}</font>


<font color="blue">char</font> FileReader<font color="black">:</font><font color="black">:</font>m_getNextChar<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font><font color="black">!</font><font color="black">(</font>linepos<font color="black">&#60;</font><font color="black">=</font>bufsize<font color="black">)</font><font color="black">)</font>
    <font color="black">{</font>
        <font color="blue">if</font><font color="black">(</font>myfile.getline<font color="black">(</font>lineBuf,BUFLEN<font color="black">)</font><font color="black">)</font>
        <font color="black">{</font>
            bufsize <font color="black">=</font> myfile.gcount<font color="black">(</font><font color="black">)</font>;<font color="green">//strlen(lineBuf);</font>
            lineBuf<font color="black">[</font>bufsize<font color="black">+</font><font color="black">+</font><font color="black">]</font> <font color="black">=</font><font color="maroon">'\n'</font>;
            linepos <font color="black">=</font> <font color="maroon">0</font>;
            <font color="blue">return</font> lineBuf<font color="black">[</font>linepos<font color="black">+</font><font color="black">+</font><font color="black">]</font>;
        <font color="black">}</font>
        <font color="blue">else</font>
        <font color="black">{</font>
            <font color="blue">return</font> EOF;
        <font color="black">}</font>
    <font color="black">}</font>
    <font color="blue">else</font> <font color="blue">return</font> lineBuf<font color="black">[</font>linepos<font color="black">+</font><font color="black">+</font><font color="black">]</font>;
<font color="black">}</font>









<font color="blue">void</font> FileReader<font color="black">:</font><font color="black">:</font>closeline<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    myfile.close<font color="black">(</font><font color="black">)</font>;
<font color="black">}</font>


<font color="blue">char</font> FileReader<font color="black">:</font><font color="black">:</font>m_getPreChar<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="black">-</font><font color="black">-</font>linepos;
    <font color="blue">return</font> lineBuf<font color="black">[</font>linepos<font color="black">+</font><font color="black">+</font><font color="black">]</font>;
<font color="black">}</font>




<font color="blue">char</font> FileReader<font color="black">:</font><font color="black">:</font>nextchar_<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="blue">return</font> myfile.get<font color="black">(</font><font color="black">)</font>;
<font color="black">}</font>



<font color="blue">void</font> FileReader<font color="black">:</font><font color="black">:</font>prechar_<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
     myfile.seekg<font color="black">(</font><font color="maroon">-1</font>,ios<font color="black">:</font><font color="black">:</font>cur<font color="black">)</font>;
     <font color="blue">return</font> ;
<font color="black">}</font>
</PRE>
</BODY>
</HTML>
